	//프로필
	function clsProfile(){
		this._HTMLDom = null;
		this.listData = null;
		this._init();	
		console.log(_util);
	}
	
	clsProfile.prototype = {
		_init: function(){
			var $layer = $("section#profile>section");
			this._HTMLDom = {
				"$layer": $layer.find("form>ul")
				, "$img": $layer.find("article.profile_area div div.p_img img")
			}						
						
			this.showTime().hide();			
		}
		, setData: function(thisData){
			this.listData = thisData;
			this.display();	
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $img = this._HTMLDom["$img"];
			var thsiClass= this;
			console.log(this.listData);
			if(this.listData["이미지"]) $img.attr("src", "/uploaded/"+this.listData["이미지"]);
			$layer.find("li:eq(0) div").html(this.listData["닉네임"]);
			$layer.find("li:eq(1) div>select>option").eq(this.listData["연령대코드"]).prop("selected",true)
			$layer.find("li:eq(1) div>select").change();
			$layer.find("li:eq(2) div>select>option").eq(this.listData["지역코드"]).prop("selected",true);
			$layer.find("li:eq(2) div>select").change();
			$layer.find("li:eq(3) div input:text").val(this.listData["직업"]);
			$layer.find("li:eq(4) div input:text").val(this.listData["핸디"]);
			$layer.find("li:eq(5) div input:text").val(this.listData["평타"]);
			
			this.showTime().show();
		}
		, spinStart: function(){		
			$.mobile.showPageLoadingMsg();			
		}
		, spinEnd: function(){			
			$.mobile.hidePageLoadingMsg();				
		}
		, showTime: function(){
			return $("section#profile>section");
		}
	}
	
	//데이터연동		
	function Profile_Comm(){
		
		this.profileList = null;		
		this.profileListRequest = null;
		
		this._init();		
	}	
	
	Profile_Comm.prototype = {
		_init: function(){
	/*		this.profileListRequest = {
				"아이디": "sjpark"
			}*/
		}
//------------------------ 프로필조회------------------------//	
		, getProfile: function(){
			var thisClass = this;
			var userId = this.profileListRequest["아이디"];
			//var userId = document.globalObj.LOGIN_DATA.userId;
			console.log(">>>>>>>>>>>>"+document.globalObj.LOGIN_DATA.userId);
			//  http://192.168.0.82:8080/sky72web/mobile/data/msp300/dl/files/free/uploaded/1344219992799.JPG
			var objJson = new MJson();
        	var cm = new ConnectionManager();
        	objJson.putPub(MJson.PUB.SID, "US001");
            objJson.putPub(MJson.PUB.SERVICENAME, "getMyProfile");
            objJson.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId);

        	cm.requestGet(objJson.getJsonString(), function(data){
				var result = [];
				console.log(data);
				if(data.msp.contents.serviceResult == "00000"){
				    var dataObj = data.msp.contents.items; 
				    console.log(dataObj);
				    //ajax
				    
                    setTimeout(function(){              
                        thisClass.profileList = {
                            "아이디": dataObj.userId
                            , "닉네임": dataObj.nickname
                            , "연령대코드": dataObj.age ? String(dataObj.age).substr(0 ,1) : ""
                            , "이미지":  _util.nvl(dataObj["saveFileName"])
                            , "지역코드": dataObj.region?dataObj.region : ''
                           // , "지역명": "중부권(강원/충청)"
                            , "직업": dataObj.job ? dataObj.job : ''
                            , "핸디":  dataObj.handi ? dataObj.handi : 0
                            , "평타": dataObj.average ? dataObj.average : 0
                        };
                        
                        $(thisClass).trigger("evtFinishProfile");
                    }, 500);  
				}
			}, function($err) {
			    console.log("errod >>>>>>>>>");
				console.log($err);
			});
			
			
			
		}
		, getProfileData: function(){
			return this.profileList;	
		}
//------------------------ 프로필조회------------------------//			
	}
	
	//컨트롤파일
	function Profile(){
		this.objComm = null;	
		this.objProfile = null;
		
	};
	
	Profile.prototype = {
	    onPageShow : function() {

	    // _util.isLogin();//로그인 체크
	      $("a").attr("href","");
	      this._init();
	    }
	    , _init: function(){	  
	    	this.objComm = new Profile_Comm();
	      	this.objProfile = new clsProfile();
	      	       
	      //프로필정보 조회
	      this.objProfile.spinStart();	      
	      this.objComm.getProfile();
	      
	      this._bind();
	    }
		 , _bind: function(){
		 	var thisClass = this;
		 	
		 	//프로필정보 조회 완료이벤트
		  	$(this.objComm).bind("evtFinishProfile", function(event){
		  		var thisData = thisClass.objComm.getProfileData();
		  		
		  		thisClass.objProfile.setData(thisData);
		  		thisClass.objProfile.spinEnd();
		  	});
		  	//handi text 입력시 자동 average 증감 event
		  	$("#profile_handi").blur( function(){
		  	   var handi =  $("#profile_handi").val();
		  	   if(isNaN(handi) ){
		  	       console.log("문자");
		  	   }else {
		  	       console.log("숫자");
		  	       $("#profile_average").val(parseInt(handi) + 72);
		  	         // $.mobile.changePage("profile_view.html");
		  	      //  $.mobile.changePage("profile_modify.html");
		  	        //$.mobile.changePage("../inc/letter_write.html");
		  	        //$.mobile.changePage("../inc/letter_view.html");
		  	   }
		  	});
		  	//설정완료 버튼
		  	$("section#profile>section>form>a").click(function(event){
		  		event.preventDefault();//기본 a tag event return;
		  		thisClass.updateProfile();			  		

		  	});
		  	// 사진등록
		  	$("#profile_camera").click( function(){
		  	    console.log("camera");
		  	});
		  	// 페이스북 연동
		  	$("#profile_facebook").on("click" , function(){
		  	    console.log("facebook");
		  	});
		  	// 개인정보 변경
		  	$("#profile_privacy").on("click" , function(){
		  	    console.log("privacy modify");
		  	    $.mobile.changePage("modify.html");
		  	});
		 }
		  , updateProfile : function(){
                	       
		        var age = $("#profile_age").val(); 
		        var region = $("#profile_region").val(); 
		        var job = $("#profile_job").val(); 
		        var handi = $("#profile_handi").val(); 
		        var average = $("#profile_average").val(); 
		        
                var objJson = new MJson();
                var cm = new ConnectionManager();
                objJson.putPub(MJson.PUB.SID, "US001");
                objJson.putPub(MJson.PUB.SERVICENAME, "updateMyProfile");
                objJson.putClient(MJson.CLIENT.USERID, document.globalObj.LOGIN_DATA.userId);
                
                objJson.putParameter("age", age);
                objJson.putParameter("region", region);
                objJson.putParameter("job", job);
                objJson.putParameter("handi", handi);
                objJson.putParameter("average", average);
               
               cm.requestGet(objJson.getJsonString(), function(data){
                  
                    console.log(data);
                    if(data.msp.contents.serviceResult == "00000"){
                        var dataObj = data.msp.contents; 
                        console.log(dataObj);
                        console.log("설정 완료");
                        alert("설정이 완료 되었습니다");
                        //특정 페이지 이동경로만 써주면 됨
                        
                    }else {
                        alert(data.msp.result.msg);
                    }
                   
                }, function($err) {
                    console.log("errod >>>>>>>>>");
                    console.log($err);
                }); 
		  }
	}
